package tedu.rocketmq.consumer;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tedu.rocketmq.service.HelloService;

@Component
@Slf4j
@RocketMQMessageListener(
        topic="test-topic-02",
        consumerGroup = "rocketmq-consumer-group-01",
        selectorExpression = "*"
)
public class MyConsumer02 implements RocketMQListener<String> {
    @Autowired
    private HelloService helloService;
    //每次推送一条消息,onMessage就执行一次
    //String message就是消息体body的反序列化数据
    @Override
    public void onMessage(String name) {
        try{
            //消费逻辑 执行消费
            System.out.println("消费者2拿到消息数据:"+name);
            //调用业务 HelloService sayHi
            helloService.sayHi(name);
        }catch (RuntimeException e){
            //做日志记录
        }
    }
}
